<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>就诊信息录入</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <script type="text/javascript" src="../js/axios.js"></script>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/message.js"></script>
    <script type="text/javascript" src="../js/sort.js"></script>
</head>
<body style="background-color: #ffaa7f;">
<div id="app">
    <fieldset style="margin-top: 100px; border-radius: 10px; border-color: #5555FF;">
        <legend style="text-align: center; color:#5555FF;font-size: 30px;">就诊信息录入</legend>
        <div class="form-group">
            <label>医保卡号*:</label>
            <input type="text" v-model="insuranceCode" @blur="insCodeCheck()"/>
            <span class="msg" v-if="insCodeFlag">{{insCodeMsg}}</span>
        </div>
        <div class="form-group">
            <label>补偿类型</label>
            <select id="sortSelect" v-model="healingSort" @change="sortCheck()">
                <option v-for="item in sortMap" :value="item.code">{{item.name}}</option>
            </select>
            <span class="msg" v-if="sortFlag">{{sortMsg}}</span>
        </div>
        <div class="form-group">
            <label>就诊时间</label>
            <input type="text" maxlength="30" v-model="healingDate" @blur="dateCheck()"/>
            <span class="msg" v-if="dateFlag">{{dateMsg}}</span>
        </div>
        <div class="form-group">
            <label></label>
            <button onclick="location.replace('visitInformation.html');">返回</button>
            <button @click="addHealing()">下一步</button>
        </div>
    </fieldset>
</div>
<script>
    var vue = new Vue({
        el: "#app",
        data: {
            insuranceCode: "",
            healingSort: 0,
            healingDate: "",
            sortMap: [],
            insCodeFlag: true,
            sortFlag: false,
            dateFlag: true,
            insCodeMsg: "",
            sortMsg: "",
            dateMsg: "",
        },
        methods: {
            insCodeCheck: function () {
                var reg = /^\d{10}$/;
                if (this.insuranceCode == null || this.insuranceCode == "") {
                    this.insCodeMsg = "请输入医保卡号";
                    this.insCodeFlag = true;
                } else if (!reg.test(this.insuranceCode)) {
                    this.insCodeMsg = "医保卡号为10位数字";
                    this.insCodeFlag = true;
                } else {
                    this.insCodeFlag = false;
                }
            },
            dateCheck: function () {
                var reg = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
                if (this.healingDate == null || this.healingDate == "") {
                    this.dateMsg = "请输入就诊日期";
                    this.dateFlag = true;
                } else if (!reg.test(this.healingDate)) {
                    this.dateMsg = "日期格式：yyyy-mm-dd，月日必须2位";
                    this.dateFlag = true;
                } else {
                    this.dateFlag = false;
                }
            },
            addHealing: function () {
                if (!this.insCodeFlag && !this.sortFlag && !this.dateFlag) {
                    axios.post("http://localhost:8000/bracelet/release/api/addhealing",
                        {
                            "insuranceCode": this.insuranceCode,
                            "healingSort": this.healingSort,
                            "healingDate": this.healingDate
                        })
                        .then(res => {
                            if (res.data.result == null) {
                                alert("添加失败!请检查医保卡号");
                            } else {
                                alert("添加成功!");
                                location.replace("visitDetailsInput.html?healingId=" + res.data.result.healingId);
                            }
                        })
                        .catch(error => {
                            location.href = "../500.html";
                        });
                }
            }
        },
        mounted: function () {
            axios.post("http://localhost:8000/bracelet/release/api/getsort",
                {
                    "sortType": SORT.补偿
                })
                .then(res => {
                    this.sortMap = res.data.result;
                })
                .catch(error => {
                    location.href = "../500.html";
                });
        }
    })
</script>
</body>

</html>
